import i18n from './static/js/i18n'
import sitemap from './static/js/sitemap'
import { defineNuxtConfig } from '@nuxt/bridge'
const envType = {
  dev: {
    NODE_ENV: 'dev',
    API_URL: 'https://api.sealmg.com',
    BASE_URL: 'https://www.sealmg.com',
    OSS_STATIC_URL: 'https://cd.sealmg.com/assets',
    API_STATIC_URL: 'https://cd.sealmg.com'
  },
  devpro: {
    NODE_ENV: 'dev',
    API_URL: 'https://api.sealmg.com',
    BASE_URL: 'https://www.sealmg.com',
    OSS_STATIC_URL: 'https://cd.sealmg.com/assets',
    API_STATIC_URL: 'https://cd.sealmg.com'
  },
  test: {
    NODE_ENV: 'test',
    API_URL: 'https://testsealmg.tikevideos.shop',
    BASE_URL: 'https://testseaimgf.tikevideos.shop',
    OSS_STATIC_URL: 'https://cd.sealmg.com/assets',
    API_STATIC_URL: 'https://cd.sealmg.com'
  },
  pro: {
    NODE_ENV: 'pro',
    API_URL: 'https://api.sealmg.com',
    BASE_URL: 'https://www.sealmg.com',
    OSS_STATIC_URL: 'https://cd.sealmg.com/assets',
    API_STATIC_URL: 'https://cd.sealmg.com'
  }
}
import { codeInspectorPlugin } from 'code-inspector-plugin'
const ENV = process.env.ENV || 'pro'
const NODE_ENV = envType[ENV]?.NODE_ENV
const apiURL = envType[ENV]?.API_URL
const baseURL = envType[ENV]?.BASE_URL
const apiStaticURL = envType[ENV]?.API_STATIC_URL
const oosStaticURL = envType[ENV]?.OSS_STATIC_URL
export default defineNuxtConfig({
  buildDir: 'nuxt-dist',
  bridge: false,
  ssr: true,
  head() {
    const i18nHead = this.$nuxtI18nHead({ addSeoAttributes: true })
    const currentLang = this.$i18n?.locale
    return {
      title: 'SEALMG  - Affordable Game Top-Ups, Gift Cards, and Digital Credits',
      htmlAttrs: {
        ...i18nHead.htmlAttrs
      },
      meta: [
        { charset: 'utf-8', hid: 'charset' },
        {
          name: 'google-site-verification',
          content: 'lbLwwJqTKOW3Tb08hmZtIpKE_0wdmrjcIRXlcFDzdHA',
          hid: 'google-site-verification'
        },
        {
          name: 'ROBOTS',
          content: 'ROBOTS',
          hid: 'ROBOTS'
        },
        {
          name: 'referrer',
          content: 'no-referrer',
          hid: 'referrer'
        },

        {
          name: 'keywords',
          hid: 'keywords',
          content:
            'sealmg, online game store, digital goods, cheap games, digital prepaid code, game card, gift card, gift certificate, digital gift card, cd-key, mobile top up, recharge mobile, mobile prepaid credits, mobile data'
        },
        {
          hid: 'og:site_name',
          property: 'og:site_name',
          content: 'SEALMG'
        },
        {
          hid: 'og:title',
          property: 'og:title',
          content: 'SEALMG - Affordable Game Top-Ups, Gift Cards, and Digital Credits'
        },
        {
          hid: 'og:description',
          property: 'og:description',
          content: 'SEALMG provides quick and secure game top-ups, gift cards, vouchers, and digital credits.'
        },
        {
          'data-n-head': 'ssr',
          name: 'viewport',
          content: 'width=device-width,initial-scale=1,minimum-scale=1,user-scalable=no',
          hid: 'viewport'
        },
        {
          'data-n-head': 'ssr',
          'http-equiv': 'X-UA-Compatible',
          content: 'IE=Edge,chrome=1',
          hid: 'X-UA-Compatible'
        },
        {
          'data-n-head': 'ssr',
          name: 'baidu-site-verification',
          content: 'mREHhDF8nW',
          hid: 'baidu-site-verification'
        },
        {
          name: 'ahrefs-site-verification',
          content: '7a3dd8803a6290d2a2afcdb62caaf207494205abfd82c52d71f58cd8dfa2b8a0',
          hid: 'ahrefs-site-verification'
        },
        {
          name: 'google-site-verification',
          content: '7MWRURExnsWNviK_7usEkdwN20HAi0H6sQW4yN9pKro',
          hid: 'google-site-verification'
        },
        ...i18nHead.meta
      ],
      link: [
        // ​ 提前与服务器建立连接
        { rel: 'preconnect', href: 'https://api.sealmg.com' },
        { rel: 'preconnect', href: 'https://cd.sealmg.com' },
        // 提前解析域名，以减少 DNS 查询时间。
        { rel: 'dns-prefetch', href: 'https://api.sealmg.com' },
        { rel: 'dns-prefetch', href: 'https://cd.sealmg.com' },
        { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
        ...i18nHead.link
      ],
      script: [
        {
          src: 'https://analytics.ahrefs.com/analytics.js',
          'data-key': 'kxxMfcJQXlXGC3YNp2F4bg',
          defer: true,
          async: true,
          type: 'text/javascript',
          charset: 'utf-8'
        },
        {
          src: 'https://www.googletagmanager.com/gtag/js?id=G-4H552ML06Y',
          async: true
        },
        {
          innerHTML:
            'window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag("js", new Date());gtag("config", "G-4H552ML06Y");',
          type: 'text/javascript',
          body: true
        }
        // {
        //   innerHTML: `
        //     CRISP_RUNTIME_CONFIG = {locale : "${currentLang}"};
        //     window.$crisp=[];
        //     window.CRISP_WEBSITE_ID="70da4493-7e7c-4a27-b885-7aec01433137";
        //     (function(){
        //       d=document;
        //       s=d.createElement("script");
        //       s.src="https://client.crisp.chat/l.js";
        //       s.async=1;
        //       d.getElementsByTagName("head")[0].appendChild(s);
        //     })();
        //   `,
        //   type: 'text/javascript',
        //   body: true
        // }
        // {
        //   src: 'https://web.cmp.usercentrics.eu/modules/autoblocker.js',
        //   async: true
        // },
        // {
        //   id: 'usercentrics-cmp',
        //   src: 'https://web.cmp.usercentrics.eu/ui/loader.js',
        //   'data-settings-id': 'nNF-nOE1mR1jMq',
        //   async: true
        // }
      ],
      __dangerouslyDisableSanitizers: ['script']
    }
  },
  loading: '~/components/GlobalLoader.vue',
  css: [
    '~/assets/css/tailwind.css',
    '~/assets/css/variables.less',
    '~/assets/css/simditor.css',
    '~/assets/css/global.css',
    'swiper/dist/css/swiper.css'
  ],
  router: {
    middleware: ['device']
  },
  plugins: [
    { src: '~/plugins/element-ui.js', ssr: false },
    { src: '@/plugins/cookies' },
    { src: '@/plugins/components.js' },
    { src: '~/plugins/router' },
    { src: '@/plugins/axios' },
    { src: '~/plugins/swiper.js', ssr: false },
    { src: '~/plugins/sticky.js', ssr: false }
  ],
  components: true,
  server: {
    http2: true,
    host: '0.0.0.0',
    port: 8041
  },
  target: 'server',
  buildModules: ['@nuxtjs/tailwindcss'],
  modules: [
    ['@nuxtjs/i18n', i18n],
    '@nuxtjs/style-resources',
    '@nuxtjs/axios',
    '@nuxtjs/proxy',
    'nuxt-precompress',
    'cookie-universal-nuxt',
    ['cookie-universal-nuxt', { parseJSON: true }],
    '@nuxtjs/sitemap',
    ['nuxt-vuex-localstorage']
  ],
  sitemap,
  styleResources: {
    less: ['~/assets/css/variables.less']
  },

  env: {
    ENV,
    NODE_ENV,
    apiURL,
    baseURL,
    apiStaticURL,
    oosStaticURL
  },
  render: {
    compressor: false
  },
  build: {
    // publicPath: `https://cd.sealmg.com/_nuxt/`,
    extend(config) {
      config.plugins.push(
        codeInspectorPlugin({
          bundler: 'webpack',
          showSwitch: true,
          hideDomPathAttr: true
        })
      )
      return config
    },
    transpile: [/^element-ui/],
    babel: {
      plugins: [
        [
          'component',
          {
            libraryName: 'element-ui',
            styleLibraryName: 'theme-chalk'
          }
        ]
      ],
      comments: true,
      presets: [
        [
          '@nuxt/babel-preset-app',
          {
            corejs: { version: 3 },
            useBuiltIns: 'usage'
          }
        ]
      ]
    },
    vendor: ['axios', 'element-ui'],
    postcss: {
      postcssOptions: {
        plugins: {
          tailwindcss: {},
          autoprefixer: {}
        }
      }
    }
  }
})
